package com.qys.livesMall.anchor.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.anchor.business.LiveRoomBusiness;
import com.qys.livesMall.anchor.model.dto.lives.app.AnchorLivesDTO;
import com.qys.livesMall.anchor.model.dto.lives.app.LikeLivesRoomDTO;
import com.qys.livesMall.anchor.model.vo.lives.app.AnchorLivesRoomVO;
import com.qys.livesMall.anchor.model.vo.lives.app.AnchorLivesVO;
import com.qys.livesMall.anchor.model.vo.lives.app.LikeListVO;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 主播直播间表 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-06-26
 */
@RestController
@Tag(name = "APP-主播直播间")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/app/anchor/lives/room")
public class AppAnchorLivesRoomController {


    private final LiveRoomBusiness liveRoomBusiness;

//    @GetMapping("/getLiveRoomBy/{livesRoomNum}")
//    @Operation(summary = "根据直播间编号查询直播间")
//    public R<Page<AnchorLivesRoomVO>> getLiveRoomBy(@PathVariable String livesRoomNum) {
//        return R.ok(livesGiftService.pageByApp(queryDTO));
//    }


    @GetMapping("/getLiveRoomBy/{livesRoomNum}")
    @Operation(summary = "根据直播间编号查询直播间详情")
    public R<AnchorLivesRoomVO> getLiveRoomBy(@PathVariable String livesRoomNum) {
        return R.ok(liveRoomBusiness.getLiveRoomBy(livesRoomNum));
    }


    @PostMapping("/giveLikeLivesRoom")
    @Operation(summary = "给直播间点赞")
    public R<Void> giveLikeLivesRoom(@RequestBody LikeLivesRoomDTO likeLivesRoomDTO) {
        liveRoomBusiness.giveLikeLivesRoom(likeLivesRoomDTO);
        return R.ok();
    }

    @GetMapping("/heatLivesRoom")
    @Operation(summary = "一小时直播间热度榜单")
    public R<List<LikeListVO>> heatLivesRoom() {
        return R.ok(liveRoomBusiness.heatLivesRoom());
    }

    @PostMapping("/getAnchorLivesRoom")
    @Operation(summary = "主播直播间集合")
    public R<IPage<AnchorLivesVO>> getAnchorLivesRoom(@RequestBody AnchorLivesDTO anchorLivesDTO){
       return R.ok(liveRoomBusiness.getAnchorLivesRoom(anchorLivesDTO));
    }

    @PostMapping("/recordViewing/{livesSessionId}")
    @Operation(summary = "记录用户观看行为")
    public R<?> recordViewing(@PathVariable Long livesSessionId){
        liveRoomBusiness.recordViewing(livesSessionId, SecurityUtils.getUserId());
        return R.ok();
    }

    @PostMapping("/getNavyNum/{livesSessionId}")
    @Operation(summary = "获取直播间水军")
    public R<?> getNavyNum(@PathVariable Long livesSessionId){
        return R.ok(liveRoomBusiness.getNavyNum(livesSessionId));
    }
}
